﻿<Window x:Class="WhoCan.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WhoCan"
        xmlns:tree="clr-namespace:TreeViewFileExplorer.ShellClasses"
        xmlns:controls="clr-namespace:WhoCan"
        d:DataContext="{d:DesignInstance {x:Type local:MainViewModel}}"
        mc:Ignorable="d"
        Title="WhoCan" Height="600" Width="1000" Closing="Window_Closing">

    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
    
    <Window.CommandBindings>
        <CommandBinding x:Name="Copy" Command="Copy" Executed="Copy_Executed" CanExecute="Copy_CanExecute" />
        <CommandBinding x:Name="Paste" Command="Paste" Executed="Paste_Executed" CanExecute="Paste_CanExecute" />
        <CommandBinding x:Name="Open" Command="Open" Executed="Open_Executed" CanExecute="Open_CanExecute" />
    </Window.CommandBindings>

    <Grid Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" MinHeight="100" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" MinHeight="100" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" MinWidth="100" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" MinWidth="100" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" MinWidth="100" />
        </Grid.ColumnDefinitions>
        
        <TreeView x:Name="FoldersControl" Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"
                  SelectedItemChanged="FoldersControl_SelectedItemChanged">
            <TreeView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="ApplicationCommands.Copy" />
                    <MenuItem Command="ApplicationCommands.Paste" />
                    <Separator/>
                    <MenuItem Command="ApplicationCommands.Open" />
                    <Separator/>
                    <MenuItem Header="Обновить" Click="MenuRefresh_Click"/>
                </ContextMenu>
            </TreeView.ContextMenu>
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
                </Style>
            </TreeView.ItemContainerStyle>
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type tree:FileSystemObjectInfo}" 
                                          ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding ImageSource, UpdateSourceTrigger=PropertyChanged}" Margin="0,1,8,1"/>
                        <TextBlock Text="{Binding FileSystemInfo.Name}"/>
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.Resources>
        </TreeView>
        
        <GridSplitter Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" ShowsPreview="False" Width="3" 
                      HorizontalAlignment="Center" VerticalAlignment="Stretch" />

        <controls:SortableListView x:Name="RulesControl" Grid.Row="0" Grid.Column="2" 
                                   ItemsSource="{Binding RuleInfos}" 
                                   SelectionChanged="RulesControl_SelectionChanged">
            <controls:SortableListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="ApplicationCommands.Copy" />
                </ContextMenu>
            </controls:SortableListView.ContextMenu>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsGroup}" Value="false">
                            <Setter Property="FontWeight" Value="Bold" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsInherited}" Value="true">
                            <Setter Property="FontStyle" Value="Italic" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Domain}" Value="false">
                            <Setter Property="Foreground" Value="Gray" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsDanger}" Value="true">
                            <Setter Property="Foreground" Value="Red" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Deny}" Value="true">
                            <Setter Property="Foreground" Value="LightGray" />
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListView.ItemContainerStyle>
            <controls:SortableListView.View>
                <GridView>
                    <GridViewColumn Header="Аккаунт" DisplayMemberBinding="{Binding PrincipalName}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="PrincipalName"/>
                    <GridViewColumn Header="Права" DisplayMemberBinding="{Binding Flags}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Flags"/>
                    <GridViewColumn Header="Подробнее" DisplayMemberBinding="{Binding Comment}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Comment"/>
                </GridView>
            </controls:SortableListView.View>
        </controls:SortableListView>
        
        <GridSplitter Grid.Row="1" Grid.Column="2" ShowsPreview="False" Height="3" 
                      HorizontalAlignment="Stretch" VerticalAlignment="Center" />
        
        <controls:SortableListView x:Name="GroupsControl" Grid.Row="2" Grid.Column="2" 
                                   ItemsSource="{Binding GroupInfos}" SelectionChanged="GroupsControl_SelectionChanged">
            <controls:SortableListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="ApplicationCommands.Copy" />
                </ContextMenu>
            </controls:SortableListView.ContextMenu>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListView.ItemContainerStyle>
            <controls:SortableListView.View>
                <GridView>
                    <GridViewColumn Header="Группа" DisplayMemberBinding="{Binding GroupName}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="GroupName"/>
                    <GridViewColumn Header="Описание" DisplayMemberBinding="{Binding Description}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Description"/>
                </GridView>
            </controls:SortableListView.View>
        </controls:SortableListView>
        
        <GridSplitter Grid.Row="0" Grid.Column="3" Grid.RowSpan="3" ShowsPreview="False" Width="3" 
                      HorizontalAlignment="Center" VerticalAlignment="Stretch" />
        
        <controls:SortableListView x:Name="UsersControl" Grid.Row="0" Grid.Column="4" Grid.RowSpan="3" 
                                   ItemsSource="{Binding UserInfos}" 
                                   SelectionChanged="UsersControl_SelectionChanged" 
                                   SelectionMode="Single">
            <controls:SortableListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="ApplicationCommands.Copy" />
                </ContextMenu>
            </controls:SortableListView.ContextMenu>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Enabled}" Value="false">
                            <Setter Property="Foreground" Value="LightGray" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsDanger}" Value="true">
                            <Setter Property="Foreground" Value="Red" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsTransit}" Value="true">
                            <Setter Property="FontStyle" Value="Italic" />
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Логин" DisplayMemberBinding="{Binding UserName}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="UserName"/>
                    <GridViewColumn Header="Имя" DisplayMemberBinding="{Binding Name}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Name"/>
                    <GridViewColumn Header="Фамилия" DisplayMemberBinding="{Binding Family}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Family"/>
                    <GridViewColumn Header="Подробнее" DisplayMemberBinding="{Binding Comment}" Width="Auto" 
                                    controls:SortableListView.SortPropertyName="Comment"/>
                </GridView>
            </ListView.View>
        </controls:SortableListView>
        
        <StatusBar Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            
            <StatusBarItem Grid.Column="0">
                <TextBlock x:Name="StatusLastWrite" Text="Готово" />
            </StatusBarItem>
            <StatusBarItem Grid.Column="1">
                <TextBlock x:Name="StatusPath" TextWrapping="Wrap" Text="Выберите папку" >
                    <TextBlock.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="ApplicationCommands.Copy" />
                            <MenuItem Command="ApplicationCommands.Paste" />
                            <MenuItem Command="ApplicationCommands.Open" />
                        </ContextMenu>
                    </TextBlock.ContextMenu>
                </TextBlock>
            </StatusBarItem>
            <StatusBarItem Grid.Column="2" HorizontalContentAlignment="Center">
                <TextBlock x:Name="StatusOwner" Text="Владелец" />
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
